var rawData = [
    [
        ["射线检测", "X射线", "2018-7-7", "xxxxx", "查看", "填写操作记录"],
        ["射线检测", "X射线", "2018-7-8", "xxxxx", "查看", "填写操作记录"],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5]],
    [
        [0, "哇啊啊啊啊啊", 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 1, 2, "哇啊啊啊啊啊", 4, 5],
        [0, "哇啊啊啊啊啊", 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, "哇啊啊啊啊啊", 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, "哇啊啊啊啊啊", 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, "哇啊啊啊啊啊", 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, "哇啊啊啊啊啊", 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5],
        [0, 1, 2, 3, 4, 5],
        [0, 2, 2, 3, 4, 5],
        [0, 3, 2, 3, 4, 5],
        [0, 4, 2, 3, 4, 5],
        [0, 5, 2, 3, 4, 5],
        [0, 6, 2, 3, 4, 5],
        [0, 7, 2, 3, 4, 5],
        [0, 8, 2, 3, 4, 5],
        [0, 9, 2, 3, 4, 5],
        [0, 10, 2, 3, 4, 5],
        [0, 11, 2, 3, 4, 5],
        [0, 12, 2, 3, 4, 5]]
];
var pageID = [1, 1];
var methodCount = [6, 6];
//设置每一页的行数
var countPerPage=[];
//默认情况下
if(user.countPerPage== 0){
    countPerPage = [10, 10];
    $('.rowNum').val(10)
}else {
    countPerPage = [user.countPerPage,user.countPerPage];
    $('.rowNum').val(user.countPerPage)
}

//点击设置每一页行数的确定按钮
$('.rowsBut').click(function () {
    //获得文本框中输入的值
    var rowsNumbuer = $('.rowNum').val();
    //将该值传入到后台中
    $.ajax({
        url:'/pj/countPerPage',
        type:'post',
        data:{'rowsNumbuer': rowsNumbuer},
        async:false,
        success:function () {
            //console.log('点击确认以后的countPerPage'+user.userId)
            if(user.countPerPage== 0){
                countPerPage = [10, 10];
                $('.rowNum').val(10)
            }else {
                countPerPage = [user.countPerPage,user.countPerPage];
                $('.rowNum').val(user.countPerPage)
            }
        },
        error:function () {
            if (status == 'error') {
                alert("你的网络有问题！");
            }
        }
    });
    //刷新页面
    location.reload()
})
var pageButtonCount = [8, 8];
var pageCount = [parseInt(rawData[0].length / countPerPage[0]) + 1, parseInt(rawData[1].length / countPerPage[1]) + 1];
var table = [document.getElementById("table0"), document.getElementById("table1")];
var tbody = [table[0].children[1], table[1].children[1]];
var pages = [document.getElementById("pages0"), document.getElementById("pages1")];
console.log(tbody[0].innerHTML);
for (var i = 0; i < 2; i++) {
    var inner = "<td>&nbsp;</td>";
    for (var j = 0; j < methodCount[i]; j++) {
        inner += "<td />";
    }
    for (var j = 0; j < countPerPage[i]; j++) {
        var tr = document.createElement("tr");
        tr.innerHTML = inner;
        tbody[i].appendChild(tr);
    }
}
for (var count = 0; count < 2; count++) {
    for (var i = 0; i < (pageCount[count] > pageButtonCount[count] ? pageButtonCount[count] : pageCount[count]); i++) {
        var li = document.createElement("li");
        li.setAttribute("onclick", "OnClick(" + (i + 1) + ", " + count + ")");
        var a = document.createElement("a");
        a.innerHTML = i + 1;
        a.setAttribute("href", "#");
        li.appendChild(a);
        pages[count].insertBefore(li, pages[count].lastElementChild);
    }
    OnClick(1, count);
}
// 生成翻页按钮
// console.log(pages[0].innerHTML);

function OnClick(index, cardIndex) {
    // console.log(cardIndex);
    // console.log("a" + pageID);
    if (index === -1) {
        console.log("b" + pageID);
        if (pageID[cardIndex] > 1) OnClick(pageID[cardIndex] - 1, cardIndex);
        return;
    }
    if (index === -2) {
        // console.log("b" + pageID);
        if (pageID[cardIndex] <= pageCount[cardIndex]) OnClick(pageID[cardIndex] + 1, cardIndex);
        return;
    }
    pageID[cardIndex] = index;
    // console.log("c" + pageID);
    //显示数据
    for (var i = 0; i < countPerPage[cardIndex]; i++) {
        if (rawData[cardIndex][(index - 1) * countPerPage[cardIndex] + i] !== undefined) {
            for (var j = 0; j < methodCount[cardIndex]; j++) {
                tbody[cardIndex].children[i].children[j].innerHTML = rawData[cardIndex][(index - 1) * countPerPage[cardIndex] + i][j];
            }
            var button = document.createElement("button");
            var info = document.createElement("i");
            info.setAttribute("class", "ace-icon fa fa-info-circle bigger-120");
            button.appendChild(info);
            button.setAttribute("class", "btn btn-xs btn-success");
            var attr = "";
            for (j = 0; j < methodCount[cardIndex]; j++) {
                attr += j === 0 ? "?" : "&";
                attr += "attr" + j + "=" + rawData[cardIndex][(index - 1) * countPerPage[cardIndex] + i][j];
            }
            button.setAttribute("onclick", "window.location.href='/projectTemp.html" + attr + "'");
            tbody[cardIndex].children[i].children[methodCount[cardIndex]].innerHTML = button.outerHTML;
        } else {
            tbody[cardIndex].children[i].children[0].innerHTML = "&nbsp;";
            for (j = 1; j < methodCount[cardIndex] + 1; j++) {
                tbody[cardIndex].children[i].children[j].innerHTML = "";
            }
        }
    }
    //刷新翻页按钮
    if (pageCount[cardIndex] > pageButtonCount[cardIndex]) {
        var first = parseInt(pageID[cardIndex] - pageButtonCount[cardIndex] / 2) + 1;
        if (first < 1) first = 1;
        if (first > pageCount[cardIndex] - pageButtonCount[cardIndex] + 1) first = pageCount[cardIndex] - pageButtonCount[cardIndex] + 1;
        for (i = 0; i < pageButtonCount[cardIndex]; i++) {
            pages[cardIndex].removeChild(pages[cardIndex].children[1]);
        }
        for (i = first; i < first + pageButtonCount[cardIndex]; i++) {
            var li = document.createElement("li");
            li.setAttribute("onclick", "OnClick(" + i + ", " + cardIndex + ")");
            if (i === pageID[cardIndex])
                li.setAttribute("class", "active");
            var a = document.createElement("a");
            a.innerHTML = i;
            a.setAttribute("href", "#");
            li.appendChild(a);
            pages[cardIndex].insertBefore(li, pages[cardIndex].lastElementChild);
        }
    } else {
        for (i = 0; i < pageCount[cardIndex]; i++) {
            pages[cardIndex].removeChild(pages[cardIndex].children[1]);
        }
        for (i = 0; i < pageCount[cardIndex]; i++) {
            li = document.createElement("li");
            li.setAttribute("onclick", "OnClick(" + (i + 1) + ", " + cardIndex + ")");
            if (i + 1 === pageID[cardIndex])
                li.setAttribute("class", "active");
            a = document.createElement("a");
            a.innerHTML = i + 1;
            a.setAttribute("href", "#");
            li.appendChild(a);
            pages[cardIndex].insertBefore(li, pages[cardIndex].lastElementChild);
        }
    }
    // console.log("d" + pageID);
}